package com.xuqm.sdhbwfu.app.viewmodel

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.xuqm.base.di.manager.HttpManager
import com.xuqm.base.extensions.showMessage
import com.xuqm.base.viewmodel.BaseListViewModel
import com.xuqm.base.viewmodel.callback.Response
import com.xuqm.sdhbwfu.app.model.ItemRiskList
import com.xuqm.sdhbwfu.app.model.RiskPureModel
import com.xuqm.sdhbwfu.app.repository.Service
import com.xuqm.sdhbwfu.core.extensions.io_main
import com.xuqm.sdhbwfu.core.extensions.subscribeBy

class RiskListViewModel : BaseListViewModel<ItemRiskList>() {


    private val _status = MutableLiveData<String>()
    val status: LiveData<String> = _status

    override fun loadData(page: Int, onResponse: Response<ItemRiskList>) {

        add(HttpManager.getApi(Service::class.java)
            .todoList(page, 10, "updateTime,desc", "risk")
            .io_main()
            .subscribeBy(
                {
                    _status.postValue(null)
                    onResponse.onResponse(it)
                }, {
                    _status.postValue(null)
                    onResponse.onResponse(null)
                    showMessage(it)
                }
            ))
    }

}